package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseCategory1;
import com.atguigu.gmall.product.entity.BaseCategory2;
import com.atguigu.gmall.product.entity.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import com.atguigu.gmall.product.service.BaseCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//以json的方式去接收前端的请求
@RestController
@RequestMapping("/admin/product")
@Api(tags = "三级分类管理")
public class BaseCategoryController {
    @Autowired
    private BaseCategoryService baseCategoryService; //一级分类
    @Autowired
    private BaseCategory2Service  baseCategory2Service; //二级分类
    @Autowired
    private BaseCategory3Service  baseCategory3Service;//三级分类
    @ApiOperation("查询所以一级分类")
    @GetMapping("/getCategory1")
    public Result getBaseCategory1(){
        List<BaseCategory1> category1 = baseCategoryService.list();
        return  Result.ok(category1);
    }
    @ApiOperation("查询所有二级请求")
   @GetMapping("/getCategory2/{category1Id}")
    public Result getBaseCategory2(@PathVariable("category1Id") Long  category1Id){
       List<BaseCategory2> category2= baseCategory2Service.getCategory2sByC1Id(category1Id);
       return  Result.ok(category2);
    }

    /**
     * 获取某个 二级目录下的三级目录
     * @param category2Id
     * @return
     */
     @GetMapping("/getCategory3/{category2Id}")
    public  Result  getBaseCategory3(@PathVariable("category2Id") Long category2Id){
      List<BaseCategory3>  category3s=   baseCategory3Service.getCategory3sByC2Id(category2Id);
        return   Result.ok(category3s);

    }



}
